#!/usr/bin/python3
import random
import datetime

max_num=1000000
#date0=20200303
nowtimestr = datetime.datetime.now().strftime('%Y%m%d')
date = int(nowtimestr)

#def GenerateRand2(date):
def GenerateRand2():
    a=1103515245
    c=12345
    m=2**31#2^32
    rand0=(a*date+c)%m
    rand=rand0%max_num
    return rand


#def Decode(qrcode,date):
def Decode(qrcode):
    #rand=GenerateRand2(date)
    rand = GenerateRand2()
    realcode = qrcode-rand
    if realcode < 0:
        realcode = max_num + qrcode - rand
    return realcode


def GenertePassCode():
    passcode=random.randint(0,max_num-1)
    return passcode


#def GenerteQRcode(passcode,date):
def GenerteQRcode(passcode):
    #rand=GenerateRand2(date)
    rand=GenerateRand2()
    qrcode=(passcode+rand)%max_num
    return qrcode


if __name__ == "__main__":
    print(nowtimestr)

    for i in range(5):
        #date = date0 #+i    
        passcode = GenertePassCode()    
        #qrcode = GenerteQRcode(passcode,date)
        qrcode = GenerteQRcode(passcode)
        #decode = Decode(qrcode,date)
        print("type qrcode: ",type(qrcode))
        decode = Decode(qrcode)
        print("type decode: ", type(decode))
        print(passcode,decode)    

        if (passcode - decode) != 0:
            print(passcode,decode,"00000000000000000000")    
        #print(rand)
